package com.ddwl.goods.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.goods.dao.mapper.AcademyCategoryMapper;
import com.ddwl.goods.dao.model.AcademyCategory;
import com.ddwl.schema.bo.goods.QueryAcademyCategoryBo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author wenbin
 */
@Repository
public class AcademyCategoryDao extends TkDao<AcademyCategoryMapper, AcademyCategory> {

    public List<AcademyCategory> queryAcademyCategory(QueryAcademyCategoryBo bo) {
        Example example = getExample();
        example.and().andEqualTo("id",bo.getId())
                .andLike("academyCategoryName", MySqlUtil.allLike(bo.getAcademyCategoryName()))
                .andEqualTo("effect",bo.getEffect())
                .andGreaterThanOrEqualTo("gmtCreated",bo.getStartTime())
                .andLessThanOrEqualTo("gmtCreated",bo.getEndTime());
        return baseMapper.selectByExample(example);
    }

    public List<AcademyCategory> selectAllWithEffect(Integer effect){
        AcademyCategory t = new AcademyCategory();
        t.setDflag(BaseEnum.DflagEnum.NOT_DELETE.getCode());
        t.setEffect(effect);
        return select(t);
    }


    public List<AcademyCategory> getList() {
        Example example = getExample();
        example.and().andEqualTo("effect",BaseEnum.StatusEnum.ENABLE.getCode());
        example.orderBy("academyCategorySort").asc();
        return baseMapper.selectByExample(example);
    }
}
